class Solution {
public:
    int height(TreeNode* root)
    {
        if (root == nullptr) return 0;
        return max(height(root->left), height(root->right)) + 1;
    }
    bool IsBalanced_Solution(TreeNode* root)
    {
        if (root == nullptr) return true;
        int left = height(root->left);
        int right = height(root->right);
        if (abs(left - right) > 1) return false;
        return IsBalanced_Solution(root->left) && IsBalanced_Solution(root->right);
    }
};